package com.jch.Dao;

import com.entity.Movie;
import com.entity.User;

import java.sql.SQLException;
import java.util.List;

public class MovieDao extends BaseDao {
    public List<Movie> queryMovie(){
        String sql="select * from Movie";

            return findList(Movie.class,sql);


    }

    public Movie queryMovie(Object...params){
        String sql="select * from Movie where mid=?";

            return findBean(Movie.class,sql,params);

    }
    public Movie queryMoviemName(Object...params){
        String sql="select * from Movie where mName=?";

        return findBean(Movie.class,sql,params);

    }

    public List<Movie> queryMovieDesc(){
        String sql="SELECT * FROM Movie ORDER BY mid DESC LIMIT 9";

        return findList(Movie.class,sql);


    }


    /**
     * 根据编号查询单条数据
     *
     * @param id
     * @return
     */
    public User queryMovie(int id) {
        String sql = "select * from movie where mId=?";
        Object[] params = {id};
        return findBean(User.class, sql, params);
    }

    /**
     * 根据实体类数据更新用户
     *
     * @param movie
     * @return
     */
    public int updateMovie(Movie movie) {
        String sql = "update movie set mName =?,mlanguage=?,mlocality=?,mPicaddress=?,mDetail=?" +
                ",mDuration=?,mType=?,mGrade=?  where mId=?";
        Object[] params = {movie.getmName(),movie.getMlanguage(),movie.getMlocality(),movie.getmPicaddress()
                ,movie.getmDetail(),movie.getmDuration(),movie.getmType(),movie.getmGrade(),movie.getMid()};
        return update(sql, params);
    }

    /**
     * 根据id删除一条数据
     *
     * @param id
     * @return
     */
    public int deleteMovie(int id) {
        String sql = "delete from movie where mId=?";
        Object[] params = {id};
        return update(sql, params);
    }

    /**
     * 根据用户对象增加一条数据
     *
     //     * @param movie
     * @return
     */
    public int insertMovie(Movie movie) {
        String sql = "insert into movie values(null,?,?,?,?,?,?,?,?)";
        Object[] params = {movie.getmName(),movie.getMlanguage(),movie.getMlocality(),movie.getmPicaddress()
                       ,movie.getmDetail(),movie.getmDuration(),movie.getmType(),movie.getmGrade()};
        return update(sql, params);
    }


}
